package com.责任链模式;


import java.util.Optional;

/**
 * 请假对象
 * @author Fang Ruichuan
 * @date 2022-09-03 11:45
 */
public class Request {
    private String name;
    private String reason;
    private int days;
    // 组长
    private String groupLeaderInfo;
    // 经理
    private String managerInfo;
    // 部门领导
    private String departmentHeaderInfo;
    // 责任信息
    private String customInfo;

    public Request(Builder builder) {
        super();
        this.name = builder.name;
        this.reason = builder.reason;
        this.days = builder.days;
        this.groupLeaderInfo = builder.groupLeaderInfo;
        this.managerInfo = builder.managerInfo;
        this.departmentHeaderInfo = builder.departmentHeaderInfo;
        this.customInfo = builder.customInfo;
    }

    public static class Builder {
        public String name;
        public String reason;
        public int days;
        public String groupLeaderInfo;
        public String managerInfo;
        public String departmentHeaderInfo;
        public String customInfo;

        public Builder() {}

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder reason(String reason) {
            this.reason = reason;
            return this;
        }

        public Builder days(int days) {
            this.days = days;
            return this;
        }

        public Builder groupLeaderInfo(String groupLeaderInfo) {
            this.groupLeaderInfo = groupLeaderInfo;
            return this;
        }

        public Builder managerInfo(String managerInfo) {
            this.managerInfo = managerInfo;
            return this;
        }

        public Builder departmentHeaderInfo(String departmentHeaderInfo) {
            this.departmentHeaderInfo = departmentHeaderInfo;
            return this;
        }

        public Builder customInfo(String customInfo) {
            this.customInfo = customInfo;
            return this;
        }

        public Builder newRequest(Request request) {
            this.name = request.name;
            this.days = request.days;
            this.reason = request.reason;
            Optional.ofNullable(request.groupLeaderInfo).ifPresent(info -> {
                this.groupLeaderInfo = info;
            });
            Optional.ofNullable(request.managerInfo).ifPresent(info -> {
                this.managerInfo = info;
            });
            Optional.ofNullable(request.departmentHeaderInfo).ifPresent(info -> {
                this.departmentHeaderInfo = info;
            });
            Optional.ofNullable(request.customInfo).ifPresent(info -> {
                this.customInfo = info;
            });
            return this;
        }

        public Request build() {
            return new Request(this);
        }
    }

    public String getName() {
        return name;
    }

    public String getReason() {
        return reason;
    }

    public int getDays() {
        return days;
    }

    public String getGroupLeaderInfo() {
        return groupLeaderInfo;
    }

    public String getManagerInfo() {
        return managerInfo;
    }

    public String getDepartmentHeaderInfo() {
        return departmentHeaderInfo;
    }

    public String getCustomInfo() {
        return customInfo;
    }

    @Override
    public String toString() {
        return "Request [name=" + name + ", reason=" + reason + ", days="
                + days + ",customInfo=" + customInfo + ", groupLeaderInfo="
                + groupLeaderInfo + ", managerInfo=" + managerInfo
                + ", departmentHeaderInfo=" + departmentHeaderInfo + "]";
    }

}
